package pers.twm.mybatis.util;

import com.intellij.openapi.util.text.StringUtil;

/**
 * @ClassName ParameterFormatUtil
 * @Description TODO
 * @Author tianwanming
 * @Date 2023/3/14 22:14
 * @Version 1.0
 */
public class ParameterFormatUtil {

    static {

    }

    private static ParameterFormatUtil parameterFormatUtil = null;
    /**
     * (String)
     * @Author twm
     * @Date 2023/3/14 22:27
     * @Param
     * @return java.lang.String
     **/
    public String format(String formatVal) {
        if(StringUtil.isEmpty(formatVal)) {
            return "";
        }

        String[] val = splitVal(formatVal);

        return val[0].trim();
    }
    /**
     *   String type = StringUtils.substringBetween(s, "(", ")");
     * @Author twm
     * @Date 2023/3/14 22:53
     * @Param
     * @return java.lang.String[]
     **/
    public String[] splitVal(String formatVal) {

        String[] result = new String[2];

        String[] splitVal = formatVal.split("\\(");
        if(splitVal.length != 2) {
            // todo 不等于2 是错误的
        }
        result[0] = splitVal[0];
        result[1] = splitVal[1].replaceAll("\\)","");
        return result;
    }

    public static String formatVal(String formatVal) {
        if(parameterFormatUtil == null) {
            parameterFormatUtil = new ParameterFormatUtil();
        }
        return parameterFormatUtil.format(formatVal);
    }
}
